package com.bw.gmalllogger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController  // @controller+@ResponseBody
@Slf4j
public class LogggerController {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    @RequestMapping("/test")
    public String test() {
        return "test";
    }

    @RequestMapping("/test1")
    public String test1(@RequestParam("name") String name,
                        @RequestParam(value = "age", defaultValue = "18") int age) {
        return name + ":" + age;
    }

    @RequestMapping("/applog")
    public String logger(@RequestParam("param") String applog) {
        // 输出log
        System.out.println(applog);
        // 打印log
        log.info(applog);
        //写到kafka
        kafkaTemplate.send("ods_base_log",applog);
        return "success";
    }
}
